package cat.joronya.supermanager.service;

import cat.joronya.supermanager.Supermanager;
import android.os.Handler;
import android.os.Message;
import android.util.Log;

/**
 * Base Handler which handles three different status on abstract methods:
 * -authError method to handle AUTH_ERROR_STATUS
 * -connectivityError method to handle CONNECTIVITY_ERROR_STATUS
 * -otherError method to handle OTHER_ERROR_STATUS
 * 
 * @author pol
 *
 */
public abstract class BaseHandler extends Handler 
{
	public static String TAG = "supermanager";
	
	// status received on message.
	public int status = -1;
	
	@Override 
    public void handleMessage(Message msg)
    { 
        //get data from msg 
        status = msg.getData().getInt(Supermanager.STATUS_MESSAGE);
        Log.d(TAG, "BaseHandler received status: "+status);
        
        if( status == Supermanager.AUTH_ERROR_STATUS )
        {
        	authError();
        }
        else if( status == Supermanager.CONNECTIVITY_ERROR_STATUS )
        {
        	connectivityError();
        }
        else if( status == Supermanager.OTHER_ERROR_STATUS )
        {
        	otherError();
        }
        
        super.handleMessage(msg);
    }
	
	/**
	 * Executed when received AUTH_ERROR_STATUS
	 */
	public abstract void authError();
	
	/**
	 * Executed when received OTHER_ERROR_STATUS
	 */
	public abstract void otherError();
	
	/**
	 * Executed when received CONNECTIVITY_ERROR_STATUS
	 */
	public abstract void connectivityError();
}
